<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { MoreActionsApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { Download } from '@/utils'
  import addForm from './addForm.vue';
  import Pagination from "@/components/Pagination/index.vue";
  const addFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const typeArr = [
    {type:1,text:'全家总动员'},
    {type:2,text:'kov'},
    {type:3,text:'2023双旦礼物销量'},
    {type:4,text:'2023双旦送礼详情'},
    {type:5,text:'概率玩法汇总数据表'},
  ]
  const listQuery = reactive({
    page:1,
    limit:20,
    type:1
  })
  const handleForm = ()=>{
    addFormRef.value.openDialog({
      typeArr
    })
  }
  const handleDownload = (row:any = {})=>{
    const { exec_url, status } = row
    if(status == 1) Download(exec_url)
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await MoreActionsApi.dataExcelList(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data || {}
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">查询类型：</div>
          <el-select @change="getList" v-model="listQuery.type" placeholder="请选择查询类型">
            <el-option
              v-for="item in typeArr"
              :key="item.type"
              :label="item.text"
              :value="item.type" />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="getList()">刷新</el-button>
          <el-button type="primary" @click="handleForm()">数据查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="80" prop="id" label="id" />
      <el-table-column min-width="120" prop="exec_url" show-overflow-tooltip label="exec_url" />
      <el-table-column min-width="120" prop="condition" label="搜素条件" />
      <el-table-column width="120" prop="type" label="类型">
        <template #default="scoped">
          {{ typeArr.find(res=>res.type == scoped.row.type)?.text || scoped.row.type }}
        </template>
      </el-table-column>
      <el-table-column width="120" prop="status" label="生成状态">
        <template #default="scoped">
          {{ ['生成中','已生成','生成失败'][scoped.row.status] || scoped.row.type }}
        </template>
      </el-table-column>
      <el-table-column width="180" prop="create_time" label="创建时间" />
      <el-table-column width="120" label="操作" >
        <template #default="scoped">
          <el-button
            :disabled="scoped.row.status==1?false:true"
            type="warning"
            @click="handleDownload(scoped.row)"
          >下载</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <addForm ref="addFormRef" @update-list="getList" />
  </div>
</template>